/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef } from 'react';
import ProTable from '@ant-design/pro-table';
import DragTable from '@/components/DragTable';
import { message } from 'antd';
import type { ActionType } from '@ant-design/pro-table';
import type { CloudBlackQueryData } from '@/components/_pages/sms/cloudBlack/index.d';
import { getColumns } from '@/components/_pages/sms/cloudBlack/index.config';
import { getBlackList } from '@/services/sms/cloudBlack';
import styles from './index.less';

const Index: React.FC = () => {
  const actionRef = useRef<ActionType>();

  const handleRequest = async (values: any) => {
    const { current: pageNum, pageSize, username, cmId } = values;
    const queryData: CloudBlackQueryData = {
      cmId,
      username,
      pageNum,
      pageSize,
    };
    const { code, data, msg } = await getBlackList(queryData);
    if (code == 0) {
      return {
        total: data.recordTotal,
        data: data.list,
      };
    } else {
      message.error(msg);
      return {};
    }
  };
  return (
    <DragTable>
      <ProTable
        className={styles.table}
        actionRef={actionRef}
        rowKey='bid'
        request={handleRequest}
        columns={getColumns(actionRef)}
        pagination={{
          pageSize: 20,
          showSizeChanger: false,
        }}
        scroll={{ x: 640 }}
        options={false}
        search={{
          collapsed: false,
        }}
      />
    </DragTable>
  );
};

export default Index;
